Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minfo.c: open device rw due to possible ioctl call #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

knarrff
Copy link
Owner

@knarrff knarrff commented May 20, 2021

This gets floppy auto configuration to work (again), i.e.:
mtools should set up the drive according to the geometry it finds when
accessing the boot sector (number of sectors, cylinders, ect). This
worked fine on my (old) machine, using the stock kernel for Debian 4.0
(yes, that old). Because it was so old, I decided to install Debian 8.0
(the last that supports the CPU). Now, mtools does not work anymore, at
least not without specifying the exact format of the disk before using
it. This is especially a problem because I do have 5.25 inch floppies
which are a mix between the (usual) 1.2MB and 1.44MB-formatted kind (and
several smaller ones). Guessing the correct format each time isn't
exactly fun, especially when you know that mtools should have the
necessary logic already built-in.

On the surface, where before

mdir b:

gave me a directory listing, using the same disk, I now get:

Can't set disk parameters for B: Operation not permitted
Cannot initialize 'B:'

This is, however, not a regression in mtools itself: the old binary is
still executable within the new Linux installation, but shows the same
problem, regardless of mtools version 3.9.10 or 4.0.18.

After reading the source of mtools and the kernel source of the floppy
driver and especially fs/block_dev.c, I see that ioctl-access is only
granted if mode & O_ACCMODE == 3. "3" is O_RDWR.

The device is opened in minfo.c within find_device(), but the mode is
one of its arguments. One usage of this is within minfo.c, but there
O_RDONLY is given as mode. Changing this to O_RDWR makes minfo work
again: the ioctl call succeeds because the FD was opened with write
permissions.

This also makes sense, as opening the device using O_RDONLY
should not allow for (those) ioctls to be sent. However, even if mtools
only plans to read from the drive, it needs to send those ioctls to
configure the drive correctly, and thus needs to open the device using
O_RDWR - which is the only thing this patch changes.

This gets floppy auto configuration to work (again), i.e.:
mtools should set up the drive according to the geometry it finds when
accessing the boot sector (number of sectors, cylinders, ect). This
worked fine on my (old) machine, using the stock kernel for Debian 4.0
(yes, that old). Because it was so old, I decided to install Debian 8.0
(the last that supports the CPU). Now, mtools does not work anymore, at
least not without specifying the exact format of the disk before using
it. This is especially a problem because I do have 5.25 inch floppies
which are a mix between the (usual) 1.2MB and 1.44MB-formatted kind (and
several smaller ones). Guessing the correct format each time isn't
exactly fun, especially when you know that mtools should have the
necessary logic already built-in.

On the surface, where before

mdir b:

gave me a directory listing, using the same disk, I now get:

Can't set disk parameters for B: Operation not permitted
Cannot initialize 'B:'

This is, however, not a regression in mtools itself: the old binary is
still executable within the new Linux installation, but shows the same
problem, regardless of mtools version 3.9.10 or 4.0.18.

After reading the source of mtools and the kernel source of the floppy
driver and especially fs/block_dev.c, I see that ioctl-access is only
granted if mode & O_ACCMODE == 3. "3" is O_RDWR.

The device is opened in minfo.c within find_device(), but the mode is
one of its arguments. One usage of this is within minfo.c, but there
O_RDONLY is given as mode. Changing this to O_RDWR makes minfo work
again: the ioctl call succeeds because the FD was opened with write
permissions.

This also makes sense, as opening the device using O_RDONLY
should not allow for (those) ioctls to be sent. However, even if mtools
only plans to read from the drive, it needs to send those ioctls to
configure the drive correctly, and thus needs to open the device using
O_RDWR - which is the only thing this patch changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant